package com.sunther.document.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sunther.document.dao.FileTagDao;
import com.sunther.document.entity.FileTagEntity;
import com.sunther.document.entity.RoleEntity;
import com.sunther.document.service.FileTagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author csb
 * @description: TODO
 * @date 2023/5/25 11:37
 */
@Service
public class FileTagServiceImpl extends ServiceImpl<FileTagDao, FileTagEntity> implements FileTagService {

    @Autowired
    private FileTagDao fileTagDao;

    @Override
    public Map<String, List<String>> getTagNameByMap() {
        List<FileTagEntity> list = list();
        Map<String, List<FileTagEntity>> collect = list.stream().collect(Collectors.groupingBy(FileTagEntity::getFileId));
        HashMap<String, List<String>> map = new HashMap<>();
        collect.forEach((k,v) -> {
            ArrayList<String> strings = new ArrayList<>();
            v.stream().forEach(a -> {
                strings.add(a.getName());
            });
            map.put(k,strings);
        });
        return map;
    }

    @Override
    public List<String> listByKeyword(String keyword, String projectId) {
        List<String> list = fileTagDao.listByKeyword(keyword, projectId);
        return list;
    }
}
